package com.sghd.candy.module.fight.manager;

import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

@Embeddable
@MappedSuperclass
public class LevelId implements Serializable, Comparable<LevelId> {
    private Integer bigLevelId;

    private Integer levelId;

    public Integer getBigLevelId() {
        return bigLevelId;
    }

    void setBigLevelId(Integer bigLevelId) {
        this.bigLevelId = bigLevelId;
    }

    public Integer getLevelId() {
        return levelId;
    }

    void setLevelId(Integer levelId) {
        this.levelId = levelId;
    }

    public static LevelId valueOf(int bigLevelId, int smallLevelId) {
        LevelId levelId = new LevelId();
        levelId.bigLevelId = bigLevelId;
        levelId.levelId = smallLevelId;
        return levelId;
    }

    public String getLevelStr() {
        return String.format("%02d", this.getBigLevelId()) + "-" + String.format("%02d", this.getLevelId());
    }

    @Override
    public int compareTo(LevelId o) {
        int i = this.bigLevelId - o.bigLevelId;
        if (i != 0){
            return i;
        }else {
            return this.levelId - o.levelId;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LevelId levelId1 = (LevelId) o;

        if (!bigLevelId.equals(levelId1.bigLevelId)) return false;
        return levelId.equals(levelId1.levelId);
    }

    @Override
    public int hashCode() {
        int result = bigLevelId.hashCode();
        result = 31 * result + levelId.hashCode();
        return result;
    }
}
